
package com.ami.kvm.imageredir;

import java.nio.ByteBuffer;

public class SCSICommandPacket {
	public static final int SCSI_TEST_UNIT_READY = 0;
	public static final int SCSI_READ_CAPACITY = 37;
	public static final int SCSI_READ_10 = 40;
	public static final int SCSI_READ_12 = 168;
	public static final int SCSI_READ_TOC = 67;
	public static final int SCSI_START_STOP_UNIT = 27;
	public static final int SCSI_MEDIUM_REMOVAL = 30;
	private int opCode;
	private byte lun;
	private int lba;
	private Cmd10 cmd10;
	private Cmd12 cmd12;

	public SCSICommandPacket(SCSICommandPacket paramSCSICommandPacket) {
		setOpCode(paramSCSICommandPacket.getOpCode());
		setLun(paramSCSICommandPacket.getLun());
		setLba(paramSCSICommandPacket.getLba());
		getCmd10().setReserved6(paramSCSICommandPacket.getCmd10().getReserved6());
		getCmd10().setLength(paramSCSICommandPacket.getCmd10().getLength());
		System.arraycopy(paramSCSICommandPacket.getCmd10().getReserved9(), 0, getCmd10().getReserved9(), 0,
				paramSCSICommandPacket.getCmd10().getReserved9().length);
		getCmd12().setLength32(paramSCSICommandPacket.getCmd12().getLength32());
		System.arraycopy(paramSCSICommandPacket.getCmd12().getReserved10(), 0, getCmd12().getReserved10(), 0,
				paramSCSICommandPacket.getCmd12().getReserved10().length);
	}

	public SCSICommandPacket(ByteBuffer paramByteBuffer) {
		setOpCode(paramByteBuffer.get() & 0xFF);

		setLun(paramByteBuffer.get());

		setLba(paramByteBuffer.getInt());

		int i;
		byte[] arrayOfByte;
		int j;
		if ((getOpCode() == 40) || (getOpCode() == 67)) {
			setCmd10(new Cmd10());

			getCmd10().setReserved6(paramByteBuffer.get());

			getCmd10().setLength(paramByteBuffer.getShort());

			i = getCmd10().getReserved9().length;
			arrayOfByte = new byte[i];
			getCmd10().setReserved9(new byte[i]);
			paramByteBuffer.get(arrayOfByte, 0, i);

			for (j = 0; j < arrayOfByte.length; j++) {
				getCmd10().getReserved9()[j] = arrayOfByte[j];
			}
		} else if (getOpCode() == 168) {
			setCmd12(new Cmd12());
			getCmd12().setLength32(paramByteBuffer.getInt());

			i = getCmd12().getReserved10().length;
			arrayOfByte = new byte[i];
			getCmd12().setReserved10(new byte[i]);
			paramByteBuffer.get(arrayOfByte, 0, i);

			for (j = 0; j < arrayOfByte.length; j++) {
				getCmd12().getReserved10()[j] = arrayOfByte[j];
			}
		}
	}

	public SCSICommandPacket() {
	}

	public Cmd10 getCmd10() {
		return this.cmd10;
	}

	public void setCmd10(Cmd10 paramCmd10) {
		this.cmd10 = paramCmd10;
	}

	public Cmd12 getCmd12() {
		return this.cmd12;
	}

	public void setCmd12(Cmd12 paramCmd12) {
		this.cmd12 = paramCmd12;
	}

	public int getOpCode() {
		return this.opCode;
	}

	public void setOpCode(int paramInt) {
		this.opCode = paramInt;
	}

	public byte getLun() {
		return this.lun;
	}

	public void setLun(byte paramByte) {
		this.lun = paramByte;
	}

	public int getLba() {
		return this.lba;
	}

	public void setLba(int paramInt) {
		this.lba = paramInt;
	}
}

